$().ready(function() {

    let type = $("#type").val();
    switch (type){
        case "1": $("#video").remove();$("#picture").remove();$("#media").remove(); $("#videoMadio").remove(); break;
        case "2": $("#articleContent").remove();$("#picture").remove();$("#media").remove();  $("#videoMadio").remove();break;
        case "3": $("#articleContent").remove();$("#video").remove();$("#media").remove(); $("#videoMadio").remove();break;
        case "4": $("#articleContent").remove();$("#video").remove();$("#picture").remove(); $("#videoMadio").remove(); break;
        case "5": $("#articleContent").remove();$("#video").remove();$("#media").remove(); $("#videoMadio").remove();break;
        case "6": $("#articleContent").remove();$("#video").remove();$("#media").remove();break;
    }

    $("#content_sn").html($("#article").val())
    $("#media_sn").html($("#mediaRich").val())

    $('#content_sn').summernote({
        height: '300px',
        lang: 'zh-CN',
        toolbar: [
            ['style', ['bold', 'italic', 'underline', 'clear']],
            ['font', ['strikethrough', 'superscript', 'subscript']],
            ['fontsize', ['fontsize']],
            ['fontname', ['fontname']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['height', ['height']],
            ['table', ['table']],
            ['insert', ['link', 'picture']],
            ['view', ['fullscreen', 'codeview', 'help']]
        ],
        callbacks: {
            onImageUpload: function (files, editor, $editable) {
                sendFiles(files,'#content_sn');
            }
        }
    });

    $('#media_sn').summernote({
        height: '300px',
        lang: 'zh-CN',
        toolbar: [
            ['style', ['bold', 'italic', 'underline', 'clear']],
            ['font', ['strikethrough', 'superscript', 'subscript']],
            ['fontsize', ['fontsize']],
            ['fontname', ['fontname']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['height', ['height']],
            ['table', ['table']],
            ['insert', ['link', 'picture']],
            ['view', ['fullscreen', 'codeview', 'help']]
        ],
        callbacks: {
            onImageUpload: function (files, editor, $editable) {
                sendFiles(files,'#media_sn');
            }
        }
    });


    //编辑器新增的ajax上传图片函数
    function sendFiles(files, editor, $editable) {
        var formData = new FormData();
        formData.append("file", files[0]);
        $.ajax({
            data : formData,
            type : "POST",
            url : "/common/sysFile/upload",    // 图片上传出来的url，返回的是图片上传后的路径，http格式
            cache : false,
            contentType : false,
            processData : false,
            dataType : "json",
            success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名
                $(editor).summernote('insertImage',data.data);
            },
            error:function(data){
                //console.log("data",data)
                alert("上传失败");
            }
        });
    }

    validateRule();

});

$.validator.setDefaults({
    submitHandler : function() {
        update();
    }
});

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            name : {
                required : true
            }
        },
        messages : {
            name : {
                required : icon + "请输入名字"
            }
        }
    })
}
